#include <iostream>
#include <fcntl.h>
#include <cstdio>
#include <cstring>
#include <unistd.h>

using namespace std;

void Snat(int fd)
{
	int fl = fcntl(fd,F_GETFL);
	if(fl < 0){
		perror("fcntl");
		return;
	}
	fcntl(fd,F_SETFL,fl | O_NONBLOCK);
}

int main()
{
	Snat(0);  /// 设置非阻塞轮询
	char buffer[1024];
	while(true){
		int n = read(0,buffer,sizeof(buffer)-1);
		if(n < 0){
			if(errno == EWOULDBLOCK){
				cout << "make a try again" << endl;
				sleep(1);
			}
			else{
				perror("read");
				break;
			}
		}
		else if(n > 0){
			buffer[n] = 0;
			cout << "echo # " << buffer << endl;
		}
	}
	return 0;
}